/**
 * ApplicationController用于定义了全局控制器材，定义菜单项的最小化，隐藏，以及面包屑显示的操作。
 * 
 * Use of Class.js
 * 
 * @author david.liu
 */

var ApplicationController = BaseController.extend({

	_location : null,
	_breadcrumb : null,

	/**
	 * 初始化应用控制器
	 * 
	 * @param $scope,
	 *            当前控制器的scope
	 * @param $location,
	 *            location服务
	 * @param breadcrumb,
	 *            面包屑的服务
	 * 
	 */
	init : function($scope, $location, breadcrumb) {

		this._location = $location;
		this._breadcrumb = breadcrumb;
		this._super($scope)
	},

	/**
	 * @Override
	 */
	defineScope : function() {
		this._handleMenuMinified();
		this._handleMenuHidden();
		this._handleMenuHighlight();

		this.$scope.breadcrumbs = this._breadcrumb;
	},

	_handleMenuMinified : function() {
		this.$scope.isMenuMinified = false;
		this.$scope.minifyMenu = function() {
			this.$scope.isMenuMinified = !this.$scope.isMenuMinified;
		}.bind(this);
	},

	_handleMenuHidden : function() {
		this.$scope.isMenuHidden = false;
		this.$scope.hiddenMenu = function() {
			this.$scope.isMenuHidden = !this.$scope.isMenuHidden;
			// Apply scoping change
			this.$scope.$apply();
		}.bind(this);
	},

	_handleMenuHighlight : function() {
		this.$scope.getActiveClass = function(path) {
			if (this._location.path().indexOf(path) >= 0) {
				return 'active';
			} else {
				return '';
			}
		}.bind(this);
	}
})

ApplicationController.$inject = [ '$scope', '$location', 'breadcrumbs' ];